package com.gientech.spring.mapper;

import com.gientech.spring.model.Coffee;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.session.RowBounds;

import java.util.List;

/**
 * @author Administrator
 */
@Mapper
public interface CoffeeMapper {

    /**
     * 新建Coffee
     * @param coffee
     * @return
     */
    @Insert("insert into t_coffee (name, price, create_time, update_time)"
            + "values (#{name}, #{price}, now(), now())")
    @Options(useGeneratedKeys = true)
    int save(Coffee coffee);

    /**
     * 查询所有Coffee
     * @param rowBounds
     * @return
     */
    @Select("select * from t_coffee order by id")
    List<Coffee> findAllWithRowBounds(RowBounds rowBounds);


    /**
     * 根据编号查找Coffee
     * @param id
     * @return
     */
    @Select("select * from t_coffee where id = #{id}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "create_time", property = "createTime"),
    })
    Coffee findById(@Param("id") Long id);

    /**
     * 查询所有Coffee
     * @return
     */
    @Select("select * from t_coffee")
    List<Coffee> findAll();

    /**
     * 更新coffee
     * @param coffee
     * @return
     */
    @Update("update t_coffee set price = #{price} where id = #{id}")
    int updateById(Coffee coffee);

    /**
     * 删除Coffee
     * @param id
     * @return
     */
    @Delete("delete from t_coffee where id = #{id}")
    int delete(@Param("id") Long id);
}
